#pragma once
#include "RBTree.h"

namespace simulation
{
	template <class K, class V>
	class Mymap
	{
		struct KeyOfMap
		{
			const K& operator()(const pair<const K, V>& data)
			{
				return data.first;
			}
		};
	public:
		typedef typename RBTree<K, pair<const K, V>, KeyOfMap>::iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, KeyOfMap>::const_iterator const_iterator;
		pair<iterator, bool> insert(const pair<const K, V>& data)
		{
			return _rbTree.insert(data);
		}
		iterator find(const K& key)
		{
			return _rbTree.find(key);
		}

		V& operator[](const K& key)
		{
			iterator it = _rbTree.insert(make_pair(key, V())).first;
			return it->second;
		}
		const_iterator find(const K& key) const
		{
			return _rbTree.find(key);
		}

		iterator begin()
		{
			return _rbTree.begin();
		}
		iterator end()
		{
			return _rbTree.end();
		}
		const_iterator begin() const
		{
			return _rbTree.begin();
		}
		const_iterator end() const
		{
			return _rbTree.end();
		}
	private:
		RBTree<K, pair<const K, V>, KeyOfMap> _rbTree;
	};
}